import requests
from lxml import etree
import urllib3
import json
import chardet
import socket
from urllib import parse
from html import unescape

urllib3.disable_warnings()
header = {
    # 'Connection': 'Keep-Alive',
    'Accept': 'text/html, application/xhtml+xml, */*',
    'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
    'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1 Edg/131.0.0.0'
}
try:
    url_str = "https://www.riben235.com/"
    # url_str = "https://www.riben235.com/sortlist/4204/time-1.html"
    # url_str = "https://www.riben235.com//sousuo/巨乳/time-1.html"
    # url_str = "https://www.riben235.com/shipin/67446286/index.html"
    # url_str ="https://www.riben235.com/movie/67446286/102137535.html"
    # ip_address = socket.gethostbyname(url_str)
    # print(ip_address)
    r = requests.get(url_str, timeout=20, headers=header,verify=False)
    r.encoding = chardet.detect(r.content)['encoding']
    # r.encoding = 'utf-8'
    html = etree.HTML(r.text)
    print(unescape(r.text))
    # js_xpath = "//div[@class='container']//script[1]/text()"
    # js_node_array = html.xpath(js_xpath)
    # video_url = ""
    # if len(js_node_array) > 0:
    #     js_str = js_node_array[0]
    #     js_str_array = js_str.split(";")
    #     js_str = js_str_array[0]
    #     js_str = js_str.replace("\"", "")
    #     js_str = js_str.replace("thisUrl = ", "")
    #     js_str = js_str.replace(" ", "")
    #     print(js_str)
    # title_node_arr = html.xpath(xpath)
    # str_1 = title_node_arr[0]
    # str_arr = str_1.split(";")
    # str_1 = str_arr[0]
    # str_1 = str_1.replace("var vod_pic = ", "")
    # str_1 = str_1.replace('"', '')
    # print(str_1)
    # for node in title_node_arr:
    #     print(node)

except BaseException as e:
    print(e)
    # print("超时")